package cn.qidisoft.edu.hzjt.service.xb.impl;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.xb.TrainingDocAttMapper;
import cn.qidisoft.edu.hzjt.model.xb.TrainingDocAttEn;
import cn.qidisoft.edu.hzjt.service.xb.ITrainingDocAttService;
import cn.qidisoft.edu.hzjt.utils.LogType;

@Service
public class TrainingDocAttServiceImpl implements ITrainingDocAttService{

	protected static final LoggerAdapter LOGGER = LoggerAdapterFactory
			.getLogger(LogType.HZJT_LOGGER.val);
	
	@Autowired
	private TrainingDocAttMapper mapper;
	
	@Override
	public void batchInserts(List<TrainingDocAttEn> records) {
		mapper.batchInserts(records);
	}

	@Override
	public int delete(TrainingDocAttEn model) {
		mapper.delete(model);
		return 0;
	}

	@Override
	public PaginationBean<TrainingDocAttEn> queryPageList(TrainingDocAttEn model, Page page) {
		try {
			int totalRecords = mapper.queryPageListcount(model);
			
			 PaginationBean<TrainingDocAttEn> pageHolder = new PaginationBean<>(page, totalRecords);
	            List<TrainingDocAttEn> resultList = mapper
	                    .queryPageList(model,
	                            new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
	                                    pageHolder.getPageSize()));
	            pageHolder.setPageList(resultList);
	            return pageHolder;
		} catch (Exception e) {
			LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                    this.getClass().getName(),
                    ToStringBuilder.reflectionToString(model, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                    e);
		}
	}

	@Override
	public TrainingDocAttEn queryByFileId(TrainingDocAttEn entity) {
		return mapper.queryByFileId(entity);
	}

}
